package com.itbour.web.action.yjx.trade;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.itbour.com.page.Page;
import com.itbour.common.base.BaseAction;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.video.YjxPriceInfoDto;
import com.itbour.service.yjx.trade.YjxPriceInfoService;
import com.opensymphony.xwork2.ActionContext;

/** 	@author 李琦 kris
 */
public class GetPriceInfoAction extends BaseAction {

	/**
	 */
	private static final long serialVersionUID = 1L;
	private YjxPriceInfoService yjxPriceInfoService;
	
	
	private String findDesc;// 套餐描述
	private String findName;// 套餐名称
	private String findPriceId;// 价格ID
	private String findState;// 套餐状态
	
	private Map<String, Object> resMap =new HashMap<String, Object>();
	public String getPriceInfo(){
		Map<String, Object> session = ActionContext.getContext().getSession();
    	UserInfoDto user = (UserInfoDto)session.get("user");
    	if (user!=null && user.getUser_id()!=null){
			HttpServletRequest request = ServletActionContext.getRequest();
			String pageNumber = request.getParameter("page");
			String pageSize = request.getParameter("rows");
			Map<String, Object> param = new HashMap<String, Object>();
			if (StringUtils.isNotEmpty(findPriceId)){
				param.put("price_id",findPriceId);
			}
			if (StringUtils.isNotEmpty(findName)){
				param.put("name",findName);
			}
			if (StringUtils.isNotEmpty(findDesc)){
				param.put("desc",findDesc);
			}
			if (StringUtils.isNotEmpty(findState)){
				param.put("state",findState);
			}
			Page page = yjxPriceInfoService.getPriceInfo(param,
					Integer.parseInt(pageNumber),
					Integer.parseInt(pageSize));
			resMap.put("total", page.getTotalCount());
			resMap.put("rows", page.getResult());
    	}		
		return SUCCESS;
	}
	public String getFindDesc() {
		return findDesc;
	}

	public void setFindDesc(String findDesc) {
		this.findDesc = findDesc;
	}

	public String getFindName() {
		return findName;
	}

	public void setFindName(String findName) {
		this.findName = findName;
	}

	public String getFindPriceId() {
		return findPriceId;
	}

	public void setFindPriceId(String findPriceId) {
		this.findPriceId = findPriceId;
	}

	public String getFindState() {
		return findState;
	}

	public void setFindState(String findState) {
		this.findState = findState;
	}
	
	private List<YjxPriceInfoDto> PriceLis;
	public String getOnePriceInfo(){
		Map<String, Object> session = ActionContext.getContext().getSession();
    	UserInfoDto user = (UserInfoDto)session.get("user");
    	if (user!=null && user.getUser_id()!=null){
			HttpServletRequest request = ServletActionContext.getRequest();
			String priceId = request.getParameter("priceId");
			Map<String, Object> parm = new HashMap<String, Object>();
			parm.put("price_id",priceId);
			PriceLis = yjxPriceInfoService.getOnePriceInfo(parm);
    	}		
		return SUCCESS;
	}
	public List<YjxPriceInfoDto> getPriceLis() {
		return PriceLis;
	}
	public void setPriceLis(List<YjxPriceInfoDto> priceLis) {
		PriceLis = priceLis;
	}
	
	

	private YjxPriceInfoDto priceDto;
	public void editPriceInfo() throws Exception{
		Map<String, Object> session = ActionContext.getContext().getSession();
    	UserInfoDto user = (UserInfoDto)session.get("user");
    	if (user!=null && user.getUser_id()!=null){
    		priceDto.setUpdate_by(user.getUser_id().toString());
    		boolean b = yjxPriceInfoService.editPriceInfo(priceDto);
    		if (b){
    			this.writeJSON("ok"); 
    		} else {
    			this.writeJSON("no"); 
    		}
    	} else {
    		this.writeJSON("no");
    	}
	}
	public YjxPriceInfoDto getPriceDto() {
		return priceDto;
	}
	public void setPriceDto(YjxPriceInfoDto priceDto) {
		this.priceDto = priceDto;
	}
	
	// 修改套餐顺序
	public void updPriceOrder() throws Exception{
		Map<String, Object> session = ActionContext.getContext().getSession();
    	UserInfoDto user = (UserInfoDto)session.get("user");
    	if (user!=null && user.getUser_id()!=null){
    		priceDto.setUpdate_by(user.getUser_id().toString());
    		Map<String, Object> parm =new HashMap<String, Object>();
    		parm.put("order", priceDto.getOrder());
    		parm.put("price_id", priceDto.getPrice_id());
    		boolean b = false;
    		if (priceDto.getPrice_id()!=null){
    			parm.put("update_by", "order:"+user.getUser_id());
    			b= yjxPriceInfoService.updPriceOrder(parm);
    		}
    		if (b){
    			this.writeJSON("ok"); 
    		} else {
    			this.writeJSON("no"); 
    		}
    	} else {
    		this.writeJSON("no");
    	}
	}
	
	
	// 删除套餐信息
	public void delPriceInfo() throws Exception{
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto)session.get("user");
		HttpServletRequest request = ServletActionContext.getRequest();
		String ids = request.getParameter("ids");
		if (user!=null && user.getUser_id()!=null && ids!=null){
			Map<String, Object> parm =new HashMap<String, Object>();
			String[] st = StringUtils.str2Array(ids);
			parm.put("ids", StringUtils.array2String(st));
			parm.put("update_by", user.getNickname()+"*"+user.getUser_id());
			boolean b = yjxPriceInfoService.dePriceInfo(parm);
			if (b){
				this.writeJSON("ok"); 
			} else {
				this.writeJSON("no"); 
			}
		} else {
			this.writeJSON("no");
		}
	}
	
	
	
	//   Set和GET
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public YjxPriceInfoService getYjxPriceInfoService() {
		return yjxPriceInfoService;
	}
	public void setYjxPriceInfoService(YjxPriceInfoService yjxPriceInfoService) {
		this.yjxPriceInfoService = yjxPriceInfoService;
	}
	public Map<String, Object> getResMap() {
		return resMap;
	}
	public void setResMap(Map<String, Object> resMap) {
		this.resMap = resMap;
	}
}
